package reflect;

import reflect.annotations.AutoRunMethod;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;

public class Test4 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();
        Method[] methods = cls.getMethods();
        for (Method method : methods) {
            if (method.isAnnotationPresent(AutoRunMethod.class)) {
                AutoRunMethod arm = method.getAnnotation(AutoRunMethod.class);
                int value = arm.value();
                System.out.println("调用方法" + method.getName() + "()"  + value + "次");
                for (int i = 0; i < value; i++) {
                    method.invoke(obj);
                }
            }
        }
    }
}
